#! /bin/bash

# modify qtopia source files to fix some compile errors.

QT_ROOT_DIR=$PWD/qtopia-free-2.2.0

pushd $QT_ROOT_DIR

# 1: pthread_yield --> sched_yield 
pushd qtopia/src/3rdparty/plugins/codecs/libffmpeg
sed -i 's/pthread_yield/sched_yield/g' mediapacketbuffer.h
popd

# 2: fix ptrdiff_t is not a name type error
pushd dqt/src/tools/
sed -i '52i\ #include <cstddef>\n #include "stddef.h" ' qvaluelist.h
popd

# 3:append ,remove function add object 
pushd qt2/src/tools
sed -i '52c\   void  push( const T& d ) { this->append(d);}' qvaluestack.h 
sed -i '57c\   this->remove( this->fromLast() );' qvaluestack.h 
popd

# 4:about <asm/page.h> header file use
pushd qt2/src/kernel
sed -i '/<asm\/page.h>/c\
#define PAGE_SHIFT   12  \
#define PAGE_SIZE  (1UL << PAGE_SHIFT) \
#define PAGE_MASK  (~(PAGE_SIZE-1)) ' qpixmapcache.cpp
popd

pushd qt2/tools/qvfb
sed -i '/<asm\/page.h>/c\
#define PAGE_SHIFT   12  \
#define PAGE_SIZE  (1UL << PAGE_SHIFT) \
#define PAGE_MASK  (~(PAGE_SIZE-1)) ' qvfbview.cpp
popd

# 5:remove class qualifier before destructor function
pushd qtopia/src/libraries/qtopia
sed -i '/\~QDawgPrivate/c\ ~QDawgPrivate()' qdawg.cpp
popd

# 6: undef macro HAVE_PROGRAM_INVOCATION_NAME
pushd qtopia/src/3rdparty/libraries/rsync
sed -i '/HAVE_PROGRAM_INVOCATION_NAME/c\#undef HAVE_PROGRAM_INVOCATION_NAME' config_linux.h
popd

# 7: open function lack the mode parameter
pushd qt2/src/tools
sed -i '143c\ f = ::open(tmpFile.latin1(), O_CREAT | O_WRONLY,0666);' qmemoryfile_unix.cpp
popd

pushd qtopia/src/libraries/qtopia
sed -i '141c\ f = ::open(tmpFile.latin1(), O_CREAT | O_WRONLY, 0666);' qmemoryfile_unix.cpp
popd

# 8: fix error: cannot find zlib.h header file
sed -i '/"zlib.h"/c\ #include "../zlib/zlib.h" ' qt2/src/3rdparty/libpng/png.h

popd

exit 0

